﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LoginModule;
using DonViNganh;
namespace HDVN5.DonViNganhPage
{
    public partial class DonViNganhHomePage : System.Web.UI.Page
    {
        private DonViNganhDataContext db = new DonViNganhDataContext();
        private string LoginId = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            // Bat dau kiem tra dieu huong trang
            if (!IsPostBack)
            {
                LoginId = Session["LOGIN_ID"].ToString();
                DieuHuongTrang(LoginId);
            }

        }

        private void DieuHuongTrang(string login)
        {
            LoginModule.AccountModuleDataContext acc = new AccountModuleDataContext();
            LoginModule.DANGKYSUDUNG dieuHuong = acc.DANGKYSUDUNGs.SingleOrDefault(p => p.TENTAIKHOAN.Trim().ToUpper() == login.Trim().ToUpper());

            if (dieuHuong != null)
            {
             
                Nullable<DateTime> ngayDau = dieuHuong.NGAYDANGNHAPLANDAU;
                if (!ngayDau.HasValue)
                {
                    Response.Redirect("/DonViNganhPage/AccountManage.aspx?user=" + login);
                }
                else
                {
                    bingToDropDownList(dieuHuong.MASO);
                }

            }
        }

        private void bingToDropDownList(Int32 madonvi)
        {
            DonViNganh.DoanSinh doanpha = new DonViNganh.DoanSinh();
            DoanPha.DataSource = doanpha.getDoanPhaDonVi(madonvi);
            DoanPha.DataBind();
        }
    }
}